package com.suwish.pc.ddms;

import javax.swing.JOptionPane;

import com.android.ddmlib.Log;
import com.android.ddmlib.Log.ILogOutput;
import com.android.ddmlib.Log.LogLevel;
import com.suwish.pc.ui.util.UIHelper;

/**
 * 
 * DDMLIB的输出监视器，实际就是日志接收器。
 * 
 * 
 * @author Min
 *
 */
public class LogHandler implements ILogOutput {

	/**
	 * 
	 * 遇到错误是否退出程序。
	 * 
	 */
	public static boolean errorExit = true;
	@Override
	public void printLog(LogLevel logLevel, String tag, String message) {
		System.out.print(Log.getLogFormatString(logLevel, tag, message));

	}

	@Override
	public void printAndPromptLog(LogLevel logLevel, String tag, String message) {
		if(LogLevel.ERROR == logLevel){
			int result = UIHelper.showFormatMessage(null, message, "Error", JOptionPane.CLOSED_OPTION);
			if(errorExit) System.exit(0);
		}
		System.err.print(Log.getLogFormatString(logLevel, tag, message));

	}

}
